home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / mgr / sparcmgr / src.zoo / src / destroy.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-17  |  5.0 KB  |  225 lines

  1. /*                        Copyright (c) 1987 Bellcore
  2.  *                            All Rights Reserved
  3.  *       Permission is granted to copy or use this program, EXCEPT that it
  4.  *       may not be sold for profit, the copyright notice must be reproduced
  5.  *       on copies, and credit should be given to Bellcore where it is due.
  6.  *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  7.  */
  8. /*    $Header: destroy.c,v 1.1 89/03/17 08:21:03 sau Exp $
  9.     $Source: /m1/mgr.new/src/RCS/destroy.c,v $
  10. */
  11. static char    RCSid_[] = "$Source: /m1/mgr.new/src/RCS/destroy.c,v $$Revision: 1.1 $";
  12.  
  13. /* destroy a window (needs fixing) */
  14.  
  15. #include "bitmap.h"
  16. #include <stdio.h>     /* temporary */
  17. #include <sys/wait.h>
  18. #include <sys/signal.h>
  19. #include "defs.h"
  20. #include "font.h"
  21. #include "event.h"
  22.  
  23. #define ALL    1
  24.  
  25. /* mark active window for destruction */
  26.  
  27. int destroy_window()
  28.    {
  29.    ACTIVE(flags) |= W_DIED;
  30.    }
  31.  
  32. /* destroy a window */
  33.  
  34. int destroy(win)
  35. register WINDOW *win;
  36.    {
  37.    int i;
  38.    union wait status;
  39.  
  40.    if (win == (WINDOW *) 0)
  41.       return(-1);
  42.  
  43.    MOUSE_OFF(mousex,mousey);
  44.    cursor_off();
  45.  
  46.    if (win != active) {
  47.       ACTIVE_OFF();
  48.       expose(win);
  49.       }
  50.  
  51.    active = W(next);
  52.  
  53.    /* deallocate window slot */
  54.  
  55.    if (active)
  56.       ACTIVE(prev) = W(prev);
  57.  
  58.    /* remove window from screen */
  59.  
  60.    erase_win(W(border));
  61.  
  62.    if (W(main)==win) {        /* kill process associated with the window */
  63. #ifdef DEBUG
  64.       dprintf(d)(stderr,"%s: destroy main %s\r\n",W(tty),W(alt)?"ALT":"");
  65. #endif
  66.       killpg(W(pid),SIGHUP);
  67.  
  68.       if (geteuid() < 1) {
  69.          chmod(W(tty),0666);
  70.          chown(W(tty),0,0);
  71.          }
  72.  
  73.       close(W(to_fd));
  74.       mask &= ~(1<<W(to_fd));
  75.       poll &= ~(1<<W(to_fd));
  76. #ifdef WHO
  77.       rm_utmp(W(tty));
  78. #endif
  79.  
  80.       /* tell alternate windows main died */
  81.  
  82.       set_dead(win);
  83.  
  84.       /* wait for shell to die */
  85.  
  86. #ifdef DEBUG
  87.       dprintf(d)(stderr,"waiting for ..."); fflush(stderr);
  88. #endif
  89.       if (W(pid) > 1) {
  90.          i = wait3(&status,WNOHANG,0L);
  91.          if (i == 0) {                     /* start it so it can die */
  92.             kill(W(pid),SIGCONT);
  93.             wait(&status);
  94.             }
  95.          }
  96. #ifdef DEBUG
  97.       dprintf(d)(stderr," %d\r\n",i);
  98. #endif
  99.       next_window--; 
  100.       }
  101.  
  102.    else if (W(main) && !(W(main)->flags&W_DIED)) {    /* main still alive */
  103. #ifdef DEBUG
  104.       dprintf(d)(stderr,"%s: destroy alt %d\r\n",W(tty),W(num));
  105. #endif
  106.       do_event(EVENT_DESTROY,win,E_MAIN);
  107.       if (W(from_fd)) {        /* re-attach output to main window */
  108.          W(main)->from_fd = W(main)->to_fd;
  109.          W(main)->max = W(max) - W(current); /* ??? */
  110. #ifdef DEBUG
  111.       dprintf(d)(stderr,"%s: copy %d chars at %d\r\n",
  112.                W(main)->max, W(current));
  113. #endif
  114.          bcopy(W(buff)+W(current)+1,W(main)->buff,W(main)->max);
  115.          W(main)->current = 0;
  116. #ifdef DEBUG
  117.          dprintf(d)(stderr,"%s: reattaching main %d chars\r\n",W(tty),W(max));
  118. #endif
  119.          }
  120.       detach(win);
  121.       }
  122.    else if (W(main)) {        /* tell main alts know they are dead */
  123.       W(main)->alt = (WINDOW *) 0;
  124. #ifdef DEBUG
  125.       dprintf(d)(stderr,"%s: destroy alt, (tell main)\r\n",W(tty));
  126. #endif
  127.       }
  128.    else {
  129. #ifdef DEBUG
  130.       dprintf(d)(stderr,"%s: destroy alt, (dead main)\r\n",W(tty));
  131. #endif
  132.       }
  133.  
  134.    /* fix up display if any windows left */
  135.  
  136.    if (active) {
  137.       repair(win);
  138.       un_covered();
  139.       clip_bad(win);    /* invalidate clip lists */
  140.       ACTIVE_ON();
  141.       cursor_on();
  142.       }
  143.  
  144.    /* free space associated with dead window */
  145.  
  146.    unlink_win(win,ALL);
  147.  
  148. #ifdef DEBUG
  149.    dprintf(d)(stderr,"Active: %s-%d\r\n",
  150.           active?ACTIVE(tty):"NONE", active?ACTIVE(num):0);
  151. #endif
  152.  
  153.    MOUSE_ON(mousex,mousey);
  154.  
  155.    return(0);
  156.    }
  157.  
  158. /* free all space associated with a window */
  159.  
  160. unlink_win(win,how)
  161. register WINDOW *win;        /* window to unlink */
  162. int how;            /* if how, unlink window stack as well */
  163.    {
  164.    register int i;
  165.  
  166. #ifdef DEBUG
  167.    dprintf(u)(stderr,"Unlinking %s %s\n",W(tty),how?"ALL":"");
  168. #endif
  169.  
  170.    if (how && W(stack))
  171.       unlink_win(W(stack),how);
  172.    if (W(window))
  173.        bit_destroy(W(window));
  174.    for(i=0; i< MAXBITMAPS;i++) 
  175.       if (W(bitmaps)[i])
  176.           bit_destroy(W(bitmaps)[i]);
  177.    if (W(border))
  178.        bit_destroy(W(border));
  179.    if (W(save))
  180.        bit_destroy(W(save));
  181.    if (W(snarf))
  182.       free(W(snarf));
  183.    if (W(bitmap))
  184.       free(W(bitmap));
  185.    zap_cliplist(win);
  186.  
  187.    for(i=0; i< MAXEVENTS;i++) 
  188.        if (W(events)[i])
  189.           free(W(events)[i]);
  190.  
  191.    for(i=0; i< MAXMENU;i++) 
  192.       if (W(menus)[i])
  193.          menu_destroy(W(menus)[i]);
  194.  
  195.    free(win);
  196.    }
  197.  
  198. /* unlink an alternate window from list */
  199.  
  200. int
  201. detach(win2)
  202. WINDOW *win2;
  203.    {
  204.    register WINDOW *win = win2;
  205.  
  206.    if (!(W(main)))
  207.       return;
  208.    for(win=win2->main;W(alt)!=win2;win=W(alt))
  209.       ;
  210.    W(alt)= win2->alt;
  211.    }
  212.  
  213. /* notify alternate windows of impending death */
  214.  
  215. set_dead(win)
  216. register WINDOW *win;
  217.    {
  218.    for(win = W(alt); win != (WINDOW *) 0; win = W(alt)) {
  219. #ifdef DEBUG
  220.       dprintf(d)(stderr,"%s: telling %d\r\n",W(tty),W(num));
  221. #endif
  222.       W(main) = (WINDOW *) 0;
  223.       }
  224.    }
  225.